package com.forum.message.listener;

import com.forum.common.event.CommentEvent;
import com.forum.message.config.RabbitMQConfig;
import com.forum.message.service.MessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 评论事件监听器
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class CommentEventListener {
    
    private final MessageService messageService;
    
    /**
     * 处理评论事件
     * 
     * @param event 评论事件
     */
    @RabbitListener(queues = RabbitMQConfig.COMMENT_QUEUE)
    public void handleCommentEvent(CommentEvent event) {
        log.info("接收到评论事件: {}", event);
        
        try {
            messageService.processMessageEvent(event);
            log.info("处理评论事件成功");
        } catch (Exception e) {
            log.error("处理评论事件失败: {}", e.getMessage(), e);
        }
    }
} 